import java.awt.*;

import javax.swing.Timer;


public class SnakeGame {

	Direction dir = Direction.RIGHT;
	private Timer timer = null;
	int currentX = 0;
	int currentY = 0;
	// Here is the callback method.
	
	public SnakeGame(Timer t) {
		timer = t;
	}
	
	
	public void updateGraphics(
			Graphics g, 
			int width, 
			int height, 
			Direction currentDirection) {
		dir = currentDirection;
		g.clearRect(0, 0, width, height);

		int currentDelay = timer.getDelay();
		if(currentDelay > 20) {
		timer.setDelay(timer.getDelay() - 1);
		}
		g.setColor(Color.black);
		// g.fillRect(xx, yy, width, height);
		// /g.setColor(Color.black);
		// g.drawRect(xx, yy, width - 1, height - 1);
		// if (loading) {

		switch(dir)
		{
		case LEFT:
			currentX -= 10;
			if(currentX < 0 ) {
				currentX = width;
			}
			g.fillRect(currentX, currentY, 10, 10);
			
			break;
		case RIGHT:
			currentX += 10;
			if(currentX > (width -10)){
				currentX = 0;
			}
			g.fillRect(currentX, currentY, 10, 10);
			break;
		case UP:
			currentY -= 10;

			if(currentY < 0 ) {
				currentY = height;
			}
			g.fillRect(currentX, currentY, 10, 10);
			break;
		case DOWN:
			currentY += 10;
			if(currentY >= (height -10) ) {
				currentY = 0;
			}

			currentX = currentX % height;
			g.fillRect(currentX, currentY, 10, 10);
			break;
		}
		// } else {
		// g.drawLine(xx + w2, yy, xx + w2, yy + height);
		// }
	}
	

}
